package wechat.custapp.corp.domain;

import com.google.common.base.Objects;
import java.util.function.Consumer;
import org.apache.log4j.Logger;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.eclipse.xtext.xbase.lib.Pure;
import wechat.base.snd.WCNews;
import wechat.base.snd.WCNewsItem;
import wechat.custapp.WCCorpCustApplication;

@SuppressWarnings("all")
public class CustomerNotificationCorp {
  private static Logger logger = Logger.getLogger("CustomerNotificationCorp");
  
  private static String CALLBACK_SERVER_URL = "http://weixin.shrct.com:8090";
  
  @Accessors
  private WCCorpCustApplication app;
  
  @Accessors
  private String cbkurl;
  
  public static CustomerNotificationCorp getIns() {
    return new CustomerNotificationCorp();
  }
  
  public String generateNotificationDetailsUrl(final String id) {
    return ((this.cbkurl + "/notificationdetail?notificationId=") + id);
  }
  
  public void sendCustomerNotification(final Iterable<String> users, final String title, final String body, final String id) {
    final Consumer<String> _function = new Consumer<String>() {
      public void accept(final String it) {
        InputOutput.<String>println(("==========>send to " + it));
      }
    };
    users.forEach(_function);
    if (((IterableExtensions.size(users) == 0) || (!IterableExtensions.<String>exists(users, new Function1<String, Boolean>() {
      public Boolean apply(final String it) {
        return Boolean.valueOf((!Objects.equal(it, null)));
      }
    })))) {
      return;
    }
    WCNews _createNews = this.app.createNews();
    final Procedure1<WCNews> _function_1 = new Procedure1<WCNews>() {
      public void apply(final WCNews it) {
        WCNewsItem _withItem = it.withItem(title);
        final Procedure1<WCNewsItem> _function = new Procedure1<WCNewsItem>() {
          public void apply(final WCNewsItem it) {
            it.setUrl(CustomerNotificationCorp.this.generateNotificationDetailsUrl(id));
          }
        };
        ObjectExtensions.<WCNewsItem>operator_doubleArrow(_withItem, _function);
        WCNewsItem _withItem_1 = it.withItem(body);
        final Procedure1<WCNewsItem> _function_1 = new Procedure1<WCNewsItem>() {
          public void apply(final WCNewsItem it) {
            it.setUrl(CustomerNotificationCorp.this.generateNotificationDetailsUrl(id));
          }
        };
        ObjectExtensions.<WCNewsItem>operator_doubleArrow(_withItem_1, _function_1);
        it.send2Users(users);
      }
    };
    ObjectExtensions.<WCNews>operator_doubleArrow(_createNews, _function_1);
  }
  
  @Pure
  public WCCorpCustApplication getApp() {
    return this.app;
  }
  
  public void setApp(final WCCorpCustApplication app) {
    this.app = app;
  }
  
  @Pure
  public String getCbkurl() {
    return this.cbkurl;
  }
  
  public void setCbkurl(final String cbkurl) {
    this.cbkurl = cbkurl;
  }
}
